package com.open.capacity.controller;

import com.open.capacity.common.entity.PlaceModel;
import com.open.capacity.common.web.Result;
import com.open.capacity.service.DateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

@RestController
@RequestMapping("/date")
public class DateController {
    @Autowired
    private DateService dateService;


    @GetMapping("/findDisable")
    public Object disable(PlaceModel placeModel){
        List<String> list= dateService.findDisable(placeModel);
        return Result.succeed(list,"操作成功");
    }

    @GetMapping("/findDate")
    public Object findNow(){
        ArrayList<String> fetureDaysList = new ArrayList<>();
        for (int i = 0; i <7; i++) {
//            pastDaysList.add(getPastDate(i));
            fetureDaysList.add(getFetureDate(i));
        }
        System.out.println(fetureDaysList);
        return Result.succeed(fetureDaysList,"操作成功");
    }

    public static String getFetureDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String result = format.format(today);
//        Log.e(null, result);
        return result;
    }
}
